package com.smartlib.cmnObject.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.smartlib.cmnObject.R;

/**
 * Created by Administrator on 2016/9/23.
 */
public class TipDialogFragment extends DialogFragment implements View.OnClickListener{
    private TextView mTvCancel, mTvOk, mTvTitle;
    private AlertDialog mAlertDialog;
    private View mView;
    private DialogOnClick onClick;
    private String mMsg;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle.containsKey("msg")) {
            mMsg = bundle.getString("msg");
        }
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mAlertDialog = new AlertDialog.Builder(getActivity(), R.style.customdialog).create();
        mAlertDialog.show();
        mView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_simple_alert, null);
        Window window = mAlertDialog.getWindow();
        window.setContentView(mView);
        initView();
        return mAlertDialog;
    }
    public void setOnClick(DialogOnClick onClick) {
        this.onClick = onClick;
    }
    private void initView() {
        mTvCancel = (TextView) mView.findViewById(R.id.dialog_tv_cancle);
        mTvOk = (TextView) mView.findViewById(R.id.dialog_tv_ok);
        mTvCancel.setOnClickListener(this);
        mTvOk.setOnClickListener(this);
        mTvTitle = (TextView) mView.findViewById(R.id.tv_title);
        mTvTitle.setText(mMsg);
    }
    @Override
    public void onClick(View v) {
        if (v == mTvCancel) {
            mAlertDialog.dismiss();
        } else if (v == mTvOk) {
            if (onClick != null) {
                onClick.onClick(null);
            }
            mAlertDialog.dismiss();
        }
    }
}
